from flask import Flask,render_template,request
import MySQLdb,json

conn = MySQLdb.connect(user='root',host='localhost',passwd='Redhat@123',db='memory')
conn.autocommit(True)
cur = conn.cursor()

app = Flask(__name__)

@app.route('/')
def index():
  return render_template('index.html')

tmp_time = 0

@app.route('/data')
def data():
  global tmp_time
  if tmp_time == '0':
    sql = 'select * from memory'
  else:
    sql = 'select * from memory where time>%s' % (tmp_time/1000)
  cur.execute(sql)
  arr = []
  for i in cur.fetchall():
    arr.append([i[1]*1000,i[0]])
  if len(arr)>0:
    tmp_time=arr[-1][0]
  return json.dumps(arr)



if __name__ == "__main__":
  app.run(host='0.0.0.0',port=80,debug=True)
